/*
package com.itheima.servlet;

import com.itheima.domian.User;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@WebServlet("/loginservlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf8");
        Map<String, String[]> parameterMap = req.getParameterMap();
        User user=new User();
        try {
            BeanUtils.populate(user,parameterMap);

            String realPath = req.getServletContext().getRealPath("/user.txt");
            System.out.println("realPath"+realPath);
            BufferedReader bufferedReader=new BufferedReader(new FileReader(realPath));
            String stu="";
            List<User>users=new ArrayList<>();
            while ((stu=bufferedReader.readLine())!=null){
                String[] split = stu.split(",");
                users.add(new User(split[0],split[1],split[2]));
            }
            bufferedReader.close();
            boolean contains = users.contains(user);
            if (contains){
                req.getSession().setAttribute("users",user);
                req.getSession().removeAttribute("msg");
                resp.sendRedirect("/listservlet");
            }else{
                req.getSession().setAttribute("msg","密码错误");
                resp.sendRedirect("/login.jsp");
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
*/
